package com.lizhaoblog.game.sbs.tmptouch.base.message;

import java.util.HashMap;
import java.util.Map;

/**
 * 〈一句话功能简述〉<br>
 * 〈Json的消息返回〉
 *
 * @author zhao
 * @date 2018/10/16 16:39
 * @since 1.0.0
 */
public class JsonRep extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public JsonRep() {
        put("code", 0);
    }

    public static JsonRep error() {
        return error(500, "未知异常，请联系管理员");
    }

    public static JsonRep error(String msg) {
        return error(500, msg);
    }

    public static JsonRep error(int code, String msg) {
        JsonRep jsonRep = new JsonRep();
        jsonRep.put("code", code);
        jsonRep.put("msg", msg);
        return jsonRep;
    }

    public static JsonRep success(String msg) {
        JsonRep jsonRep = new JsonRep();
        jsonRep.put("msg", msg);
        return jsonRep;
    }

    public static JsonRep success(Map<String, Object> map) {
        JsonRep jsonRep = new JsonRep();
        jsonRep.putAll(map);
        return jsonRep;
    }

    public static JsonRep success() {
        return new JsonRep();
    }

    @Override
    public JsonRep put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
